<template>
    <header>
      <!-- 定位 -->
        <span class="location" @click="showLocationDialog()">
            <i class="iconfont icon-dingwei"></i>
            <span>{{lacationValue.name}}</span>
        </span>

      <!-- search ,组件插槽-->
        <slot name="center" class="input"></slot>

      <!-- 登录注册 -->
        <span v-show="userData._id" class="personal" @click="$router.push('/personal')">
             <i class="iconfont icon-huiyuan"></i>
        </span>
        <span v-show="!userData._id" class="login" @click="showLoginDialog()">
            登录|注册
        </span>

        <!-- 定位选择弹窗 -->
        <van-dialog v-model="showLocation" title="选择你的定位信息" :show-confirm-button='false'>
            <van-area
            confirm-button-text='确认'
            cancel-button-text= '取消'
            visible-item-count=3
            :columns-num="2"
            :area-list="areaList"
            :value="lacationValue.code"
            @confirm=confirmLocation
            @cancel=cancelLocation
            />
        </van-dialog>
        <!-- 登录弹窗 -->
        <van-dialog v-model="showLoginWay"
        title="选择登录方式" :show-confirm-button='false'
        :close-on-click-overlay='true'
        show-cancel-button>
            <div class="login_btns">
                <button @click="$router.push('/login/1')">短信登录</button>
                <button @click="$router.push('/login/0')">账号登录</button>
            </div>
        </van-dialog>
    </header>
</template>

<script>
import { mapState } from 'vuex'

export default {
  data: function () {
    return {
      showLocation: false,
      showLoginWay: false,
      lacationValue: { code: '120200', name: '东湖区' },
      areaList: {
        province_list: {
          110000: '景德镇市',
          120000: '南昌市',
          130000: '萍乡市'
        },
        city_list: {
          110100: '珠山区',
          110200: '昌江区',
          110300: '乐平市',
          110400: '浮梁县',
          110500: '其他',
          120100: '西湖区',
          120200: '东湖区',
          120300: '青云谱区',
          120400: '湾里区',
          120500: '青山湖区',
          120600: '新建县',
          120700: '南昌县',
          120800: '进贤县',
          120900: '安义县'
        }
      }
    }
  },
  // 通过props传值
  computed: {
    ...mapState(['address', 'userData'])
  },
  methods: {
    showLoginDialog () {
      this.showLoginWay = true
    },
    showLocationDialog () {
      this.showLocation = true
    },
    confirmLocation (value) {
      this.lacationValue = value[1]
      this.showLocation = false
    },
    cancelLocation () {
      this.showLocation = false
    }
  }
}
</script>

<style lang="less" scoped>
header {
    position: fixed;
    z-index: 999;
    width: 100%;
    top: 0;
    height: 50px;
    background-color: #58D493;
    display: flex;
    flex-wrap: nowrap;
    flex-direction: row;
    justify-content: space-around;
    line-height: 50px;
    & .location {
        font-size: 12px;
        color: #F1F1F1;
        text-align: center;
        width: 80px;
        & i{
            font-size: 32px;
            line-height: 50px;
            margin-left: 10px;
            color: #F1F1F1;
        }
    }
    & .login , .personal{
        line-height: 50px;
        width: 80px;
        font: 18px;
        color: #F1F1F1;
        margin-right: 10px;
        text-align: center;
        & i{
            font-size: 30px;
        }
    }
}
.login_btns {
    margin-top: 15px;
    margin: 18px auto;
    width: 36%;
    & button {
        width: 100%;
        height: 40px;
        font-size: 13px;
        border-radius: 10px;
        background-color: #f5f5f5;
        color: #58D493;
        line-height: 40px;
    }
}
</style>
